home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
- Newsgroups: comp.std.c++
- Subject: How it auto_ptr currently defined?
- Date: 15 Apr 1996 09:35:51 PDT
- Organization: FakultΣt fⁿr Mathematik und Informatik
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <4ko4cv$ao7@news.BelWue.DE>
- Reply-To: dietmar.kuehl@uni-konstanz.de
- NNTP-Posting-Host: isolde.mti.sgi.com
- Summary: How are the copy semantics of 'auto_ptr' currently defined?
- Keywords: auto_ptr, copy ctor
- X-Original-Date: 13 Apr 1996 11:49:51 GMT
- X-Newsreader: TIN [version 1.2 PL2]
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMXJ66Ey4NqrwXLNJAQEzHQH+KuFE9qOMouQD1z98VXV7hdfWugd1iR6h
- h0f6mQCv8X1Km3EQiaWKFzflELyDi9YK28jKjY/ikfO9o/Z2qrIzTg==
- =g6cc
- Originator: austern@isolde.mti.sgi.com
-
- Hi,
-
- gregor@netcom.com (Greg Colvin) recently posted a sample implementation
- of 'auto_ptr' to this forum. With his implementation, the following
- code would be well defined:
-
- #include <auto_ptr>
-
- auto_ptr<int> f(auto_ptr<int> ptr) { return ptr; }
-
- int main()
- {
- auto_ptr<int> p1(new int(17));
- auto_ptr<int> p2 = f(p1);
- return *p1;
- }
-
- The key point I'm confused about, is that 'p1' holds a valid pointer
- even after copying the pointer when creating the argument for the
- function 'f()': The 'get()' member function of an 'auto_ptr' apparently
- returns the correct value even if the pointer is not owned by the
- 'auto_ptr' (in the above case, the pointer is owned by 'p2' not by
- 'p1'). This might result in an 'auto_ptr' holding a stale pointer.
-
- As I have no access to the changes made at the last committee meeting,
- my question is this: Is the above code required to be well defined for
- a standard conforming implementation? The thread where Greg Colvin
- posted his version of 'auto_ptr' implies that the standard will require
- the above code to be well defined but there was no explicit statement
- about this. The above code resulted in undefined behavior according to
- the April DWP (because the copy ctor of 'auto_ptr' was defined to
- implicitly call 'release()').
-
- Thank you very much for any responses
- dk
- --
- dietmar.kuehl@uni-konstanz.de
- http://www.informatik.uni-konstanz.de/~kuehl/
- I am a realistic optimist - that's why I appear to be slightly pessimistic
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-